const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = (env) => {
    return {
        mode:'development',
        output:{
            filename:'index.js',
            path:path.resolve(__dirname,'dist'),
            libraryTarget:env.production?'system':'' //打包的格式：模块规范 system模式，默认自执行函数
        },
        module:{
            rules:[
                {
                    test:/\.js$/,
                    use:{loader:'babel-loader'},
                    exclude:/node_modules/
                }
            ]
        },
        plugins:[
            !env.production&&new HtmlWebpackPlugin({
                template:'./public/index.html'
            })
        ].filter(Boolean),
        //公共模块不重复打包
        externals:env.production?["react","react-dom"]:[]
    }
}